public class Main {
        static class ListNode {
            int val;
            ListNode next = null;

            ListNode(int val) {
                this.val = val;
            }
        }
        ListNode head = null;
        public void creat(){
            ListNode list1 = new ListNode(1);
            ListNode list2 = new ListNode(2);
            ListNode list3 = new ListNode(2);
            ListNode list4 = new ListNode(1);

            list1.next=list2;
            list2.next=list3;
            list3.next=list4;

            head=list1;
        }

    public boolean chkPalindrome(ListNode A) {
        if (A == null) return false;
        ListNode slow = A;
        ListNode fast = A;
        ListNode list = A;
        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
        }
        ListNode cur1 = slow.next;
        while (cur1 != null) {
            ListNode cur2 = cur1.next;
            cur1.next = slow;
            slow = cur1;
            cur1 = cur2;
        }
        while (list.next != slow && list != slow) {
            if (list.val != slow.val) return false;
            list = list.next;
            slow = slow.next;
        }
        return true;
    }
}